import cv2 as cv
import sys
import os
from python_ai.common.xcommon import *
import matplotlib.pyplot as plt
import numpy as np
import time
import datetime


def my_show_img(img, title="no title", trans=None):
    global spn
    spn += 1
    plt.subplot(spr, spc, spn)
    if trans is not None:
        img = trans(img)
    plt.imshow(img)
    plt.axis('off')
    plt.title(title)


img_dir = '../../../../large_data/pic'
img_path1 = os.path.join(img_dir, 'DSC05022_1.JPG')
img_path2 = os.path.join(img_dir, 'DSC05039.JPG')

spr = 2
spc = 2
spn = 0
plt.figure(figsize=[10, 10])

sep('load')
img1 = cv.imread(img_path1, cv.IMREAD_UNCHANGED)
img2 = cv.imread(img_path2, cv.IMREAD_UNCHANGED)
print(img1.shape)
print(img2.shape)

my_show_img(img1, 'img1', lambda x: cv.cvtColor(x, cv.COLOR_BGR2RGB))
my_show_img(img2, 'img2', lambda x: cv.cvtColor(x, cv.COLOR_BGR2RGB))

sum1 = cv.add(img1, img2)
my_show_img(sum1, 'sum1 by cv', lambda x: cv.cvtColor(x, cv.COLOR_BGR2RGB))

sum2 = img1 + img2
my_show_img(sum1, 'sum2 by numpy', lambda x: cv.cvtColor(x, cv.COLOR_BGR2RGB))
